package com.youi.util;

import java.util.HashMap;
import java.util.Map;

public class CommonUtil {


    /**
     * 解析url参数
     *
     * @param url
     */
    public static Map<String,Object> parseUrl(String url) {
        Map<String,Object> map = new HashMap();
        if (url == null) {
            return map;
        }
        url = url.trim();
        if (url.equals("")) {
            return map;
        }
        String[] urlParts = url.split("\\?");
        map.put("baseUrl",urlParts[0]);
        //没有参数
        if (urlParts.length == 1) {
            return map;
        }
        //有参数
        String[] params = urlParts[1].split("&");
        for (String param : params) {
            String[] keyValue = param.split("=");
            map.put(keyValue[0], keyValue[1]);
        }
        return map;
    }

    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) {
        Map<String,Object> map = new HashMap();
        map = parseUrl("");
        System.out.println(map.toString());
    }

}
